/*
    12. Write a C program to remove the duplicates from a given array of integers. Go to the editor
    Expected Output:

    Original array:
    1 1 2 3 4 4 5 6 6 6 
    After removing duplicates from the above sorted array:
    1 2 3 4 5 6
*/

#include <stdio.h>
#include <stdlib.h>

void printArray(int a[], int len){
    int i;
    for(i = 0; i < len; i++){
        printf("%d ", a[i]);
    }
    printf("\n");
}

int main(void)
{
    int a[] = {1,1,2,3,4,4,5,6,6,6};
    int len = sizeof(a) / sizeof(int);
    int *b = (int *)malloc(sizeof(a));
    int i, j;
    printf("Original array:\n");
    printArray(a, len);
    for(i = 0, j = 0, b[j] = a[i]; i < len; i++){
        if(a[i] != b[j]){
            j++;
            b[j] = a[i];
        }
    } 
    printf("After removing duplicates from the above sorted array:\n");
    printArray(b, j + 1);

    free(b);

    return 0;
}